export default option => {
  let {
    store,
    name,
    computed,
    methods,
  } = option;

  if (typeof name !== 'undefined')name = name.toUpperCase();

  if (typeof store !== 'undefined') {
    delete option.store;
    autoVueStoreState();
    autoVueStoreGetters();
    autoVueStoreDictionary();
  }

  function autoVueStoreDictionary () {
    option.methods['DICTIONARY'] = function (DICTIONARY, val) {
      /**
       *
       * @param index
       * @param value
       * @returns {*}
       * @constructor
       */
      function DictionarySearch (index, value) {
        if (value.constructor !== Array) return DICTIONARY[index][value];
        let step = '';
        let signal = '\\';
        for (let item of value) {
          step += DICTIONARY[index][item + ''] + signal;
        }
        step = step.substring(0, step.length - 1);
        return step;
      }
      let step = {};
      for (let index in val) {
        if (val.hasOwnProperty(index)) {
          step['show_' + index] = DictionarySearch(index, val[index]);
        }
      }
      return step;
    };
  }
  function autoVueStoreState () {
    let computedStep = {};
    if (store.constructor !== Object) {
      let sStep = {};
      if (store.constructor === Array) {
        for (let index of store) {
          autoVueStoreStateInner(sStep, index);
        }
      } else {
        autoVueStoreStateInner(sStep, store);
      }
      computedStep = {
        ...computedStep,
        ...sStep,
      };
    } else {
      let {s} = store;
      if (typeof s !== 'undefined') {
        let sStep = {};
        if (s.constructor === Array) {
          for (let index of s) {
            autoVueStoreStateInner(sStep, index);
          }
        } else {
          autoVueStoreStateInner(sStep, s);
        }
        computedStep = {
          ...computedStep,
          ...sStep,
        };
      }
    }

    option.computed = {
      ...computed,
      ...computedStep,
    };
    option.methods = {
      ...methods,
      ...{
        SET: function (key, value) {
          let keyword = 'SET';
          if (/^[A-Z]*$/.test(key)) {
            return this.$store.commit(key + '/' + keyword, value);
          } else if (key.indexOf('_') !== -1) {
            let step = key.split('_');
            if (step[0] === 'S') {
              return this.$store.commit(keyword + '_' + key, value);
            } else {
              return this.$store.commit(step[0] + '/' + keyword + '_' + step[1], value);
            }
          } else {
            return this.$store.commit(name + '/' + keyword + '_' + key, value);
          }
        },
        DEL: function (key, value) {
          let keyword = 'DEL';
          if (/^[A-Z]*$/.test(key)) {
            return this.$store.commit(key + '/' + keyword, value);
          } else if (key.indexOf('_') !== -1) {
            let step = key.split('_');
            if (step[0] === 'S') {
              return this.$store.commit(keyword + '_' + key, value);
            } else {
              return this.$store.commit(step[0] + '/' + keyword + '_' + step[1], value);
            }
          } else {
            return this.$store.commit(name + '/' + keyword + '_' + key, value);
          }
        },
        USE: function (key, value) {
          let keyword = 'USE';
          if (/^[A-Z]*$/.test(key)) {
            return this.$store.dispatch(key + '/' + keyword, value);
          } else if (key.indexOf('_') !== -1) {
            let step = key.split('_');
            if (step[0] === 'S') {
              return this.$store.dispatch(keyword + '_' + key, value);
            } else {
              return this.$store.dispatch(step[0] + '/' + keyword + '_' + step[1], value);
            }
          } else {
            return this.$store.dispatch(name + '/' + keyword + '_' + key, value);
          }
        },
      },
    };
    function autoVueStoreStateInner (sStep, index) {
      if (/^[A-Z]*$/.test(index)) {
        sStep[index] = function () {
          return this.$store.state[index];
        };
      } else if (index.indexOf('_') !== -1) {
        let step = index.split('_');
        if (step[0] === 'S') {
          sStep[index] = function () {
            return this.$store.state[index];
          };
        } else {
          sStep[index] = function () {
            return this.$store.state[step[0]][step[1]];
          };
        }
      } else {
        sStep[index] = function () {
          return this.$store.state[name][index];
        };
      }
    }
  }

  function autoVueStoreGetters () {
    let {g} = store;
    if (g) {
      let sStep = {};
      if (g.constructor === Array) {
        for (let index of g) {
          autoVueStoreGettersInner(sStep, index);
        }
      } else {
        autoVueStoreGettersInner(sStep, g);
      }
      option.computed = {
        ...option.computed,
        ...sStep,
      };
    }

    function autoVueStoreGettersInner (sStep, index) {
      if (/^[A-Z]*$/.test(index)) {
        sStep[index] = function () {
          return this.$store.getters[index];
        };
      } else if (index.indexOf('_') !== -1) {
        let step = index.split('_');
        if (step[0] === 'S') {
          sStep[index] = function () {
            return this.$store.getters[index];
          };
        } else {
          sStep[index] = function () {
            return this.$store.getters[step[0] + '/' + step[1]];
          };
        }
      } else {
        sStep[index] = function () {
          return this.$store.getters[name][index];
        };
      }
    }
  }
};
